package com.app.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.alibaba.fastjson.JSON;
import com.app.entity.User;
import com.app.entity.vo.UserVo;
import com.app.form.UserLoginForm;
import com.app.mapper.UserMapper;
import com.app.service.UserService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.injector.methods.SelectOne;
import com.baomidou.mybatisplus.core.toolkit.BeanUtils;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author yeyuan
 * @since 2021-11-27
 */
@Service
@Slf4j
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {

    @Override
    public UserVo Login(UserLoginForm userLoginForm) {

        LambdaQueryWrapper<User> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(StringUtils.isNotEmpty(userLoginForm.getUsername()),User::getName,userLoginForm.getUsername());
        User user = baseMapper.selectOne(wrapper);
        UserVo userVo = new UserVo();
        log.info("userVo:",JSON.toJSON(user));
        BeanUtil.copyProperties(user,userVo);
        user.setId(userVo.getId());
        return userVo;
    }
}
